<?php

namespace Laoha\Blog;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;

class BlogServiceProvider extends ServiceProvider
{
    /**
     * {@inheritdoc}
     */
    public function boot(Blog $extension)
    {
        if ($views = $extension->views()) {
            $this->loadViewsFrom($views, 'blog');
        }

        //数据迁移
        if ($this->app->runningInConsole()) {
            $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
        }
        Blog::boot();
        $this->app->booted(function () {
            $this->adminRoutes();
            $this->apiRoutes();
        });

    }

    /**
     * Register the admin routes.
     *
     * @return void
     */
    protected function adminRoutes()
    {
        Route::group([
            'prefix'        => config('admin.route.prefix'),
            'middleware'    => config('admin.route.middleware'),
            'namespace'     => 'Laoha\Blog\Admin\Controllers',
            'as'	 => 'admin.',
        ], function () {
            $this->loadRoutesFrom(__DIR__.'/../routes/admin.php');
        });
    }

    /**
     * Register the api routes.
     *
     * @return void
     */
    protected function apiRoutes()
    {
        Route::group([
            'middleware' => ['api'],
            'namespace' => 'Laoha\Blog\Api\Controllers',
            'prefix' => 'api',
            'as'	 => 'api.',
        ], function () {
            $this->loadRoutesFrom(__DIR__.'/../routes/api.php');
        });
    }
}